<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2017/12/12
  Time: 17:45
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>销售应收</title>
    <jsp:include page="../headPage.jsp"></jsp:include>
    <script type="text/javascript">
        $(function () {

            //1.初始化Table
            var oTable = new TableInit();
            oTable.Init();

            //2.初始化Button的点击事件
            var oButtonInit = new ButtonInit();
            oButtonInit.Init();

        });


        var TableInit = function () {
            var oTableInit = new Object();
            //初始化Table
            oTableInit.Init = function () {
                $('#tb_departments').bootstrapTable({
                    //url: '/pages/yzlERP/data/salesReceivable.json',         //请求后台的URL（*）
                    url: '${pageContext.request.contextPath }/hpf/receivableList.do',         //请求后台的URL（*）
                    method: 'post',                      //请求方式（*）
                    contentType:"application/x-www-form-urlencoded; charset=UTF-8",
                    toolbar: '#toolbar',                //工具按钮用哪个容器
                    striped: true,                      //是否显示行间隔色
                    cache: false,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
                    pagination: true,                   //是否显示分页（*）
                    //queryParamsType: "limit",
                    //contentType: "application/x-www-form-urlencoded",
                    sortable: false,                     //是否启用排序
                    sortOrder: "asc",                   //排序方式
                    queryParams: oTableInit.queryParams,//传递参数（*）
                    sidePagination: "server",           //分页方式：client客户端分页，server服务端分页（*）
                    pageNumber: 1,                       //初始化加载第一页，默认第一页
                    pageSize: 10,                       //每页的记录行数（*）
                    pageList: [10, 20, 30],        //可供选择的每页的行数（*）
                    //search: true,                       //是否显示表格搜索，此搜索是客户端搜索，不会进服务端，所以，个人感觉意义不大
                    strictSearch: true,
                    //showColumns: true,                  //是否显示所有的列
                  	//showRefresh: true,                  //是否显示刷新按钮
                    minimumCountColumns: 2,             //最少允许的列数
                    //clickToSelect: true,                //是否启用点击选中行
                    height: 500,                        //行高，如果没有设置height属性，表格自动根据记录条数觉得表格高度
                    //uniqueId: "ID",                     //每一行的唯一标识，一般为主键列
                    //showToggle: true,                    //是否显示详细视图和列表视图的切换按钮
                    //cardView: false,                    //是否显示详细视图
                    //detailView: false,                   //是否显示父子表
                    columns: [
                        {
                            field: 'id',
                            title: 'ID',
                            visible: false,
                        }, {
                            field: 'name',
                            title: '客户名称'
                        }, {
                            field: 'customerId',
                            title: '客户编号'
                        }, {
                            field: 'type',
                            title: '客户类型'
                        }, {
                            field: 'enter',
                            title: '业务员'
                        }, {
                            field: 'dateMonth',
                            title: '日期'
                        }, {
                            field: 'lastMonthP',
                            title: '期初应收'
                        }, {
                            field: 'outAmount',
                            title: '本期出库金额',
                            formatter: function (value, row, index) {
                            	if (row.outAmount>0) {
                            		return row.outAmount;
                            	} else {
                            		return 0;
                            	}
                            }
                        }, /* {
                            field: 'thisMonthlastP',
                            title: '本期到期收款金额'
                        }, {
                            field: 'monthReceivableP',
                            title: '本期应收金额'
                        },  */{
                            field: 'monthCollectP',
                            title: '本期收款金额'
                        }, {
                            field: 'monthCollectionP',
                            title: '本期待收金额'
                        }, {
                            field: 'closingBalanceP',
                            title: '期末应收'
                        }/* , {
                            field: 'seeDetails',
                            title: '结算',
                            formatter: function (value, row, index) {
                                return '<a href="#" onclick="jiesuanYs(' + index + ')">结算</a>'
                            }
                        } */]
                });
            };

            //得到查询的参数
            oTableInit.queryParams = function (params) {
                var temp = {   //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
                    limit: params.limit,   //页面大小
                    offset: params.offset / params.limit + 1,  //页码
                    demandDate: $("#demandDate_serch").val(),
                    produceStatus: $("#produceStatus_serch").val(),
                    outLibraryStatus: $("#outLibraryStatus_serch").val(),
                    /* customerId: $("#customerId_serch").val(), */
                    entryPerson: $("#entryPerson_serch").val(),
                };
                return temp;
            };
            return oTableInit;
        };


        var ButtonInit = function () {

            var oInit = new Object();
            var postdata = {};

            oInit.Init = function () {
                //初始化页面上面的按钮事件
            };
            return oInit;
        };
    </script>
</head>
<body>
<div class="panel-body" style="padding-bottom:0px;">
    <div class="panel panel-default">
        <div class="panel-heading">查询条件</div>
        <div class="panel-body">
            <form id="formSearch" class="form-horizontal">
                <div class="form-group" style="margin-top:15px">
                    <label class="control-label col-sm-1">日期:</label>
                    <!-- <div class="col-sm-1">
                        <select id="recent" name="recent"
                                class="selectpicker show-tick form-control" data-live-search="false">
                            <option value="0">无</option>
	                        <option value="1">最近一天</option>
	                        <option value="7">最近一星期</option>
	                        <option value="30">最近一个月</option>
                        </select>
                    </div> -->
                    <!-- <label class="control-label col-sm-1" for="beginDate" style="width: 30px;">从</label> -->
                    <div class="col-sm-2">
                        <input type="text" name="beginDate" id="beginDate" placeholder="yyyy-mm" class="form_datetime form-control">
                    </div>
                    <!-- <label class="control-label col-sm-1" for="endDate" style="width: 30px;padding-left: 0px;">至</label>
                    <div class="col-sm-2" style="padding-left: 0px;">
                        <input type="text" name="endDate" id="endDate" lay-verify="date"
                               placeholder="yyyy-mm-dd"
                               autocomplete="off" class="layui-input form-control"
                               onclick="layui.laydate({elem: this})">
                    </div> -->
                    <div class="col-sm-1" style="text-align:left;">
                        <button type="button" style="margin-left:50px" id="btn_query" class="btn btn-primary">查询
                        </button>
                    </div>
                </div>
            </form>
        </div>
    </div>

    <!-- <div id="toolbar" class="btn-group">
        <button id="btn_report" type="button" class="btn btn-default">
            <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>图形报表
        </button>
        <button id="btn_edit" type="button" class="btn btn-default">
            <span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>导出
        </button>
        <button id="btn_delete" type="button" class="btn btn-default">
            <span class="glyphicon glyphicon-remove" aria-hidden="true"></span>打印
        </button>
        <button id="btn_jiesuanAll" type="button" class="btn btn-default">
            <span class="glyphicon glyphicon-remove" aria-hidden="true"></span>所有结算
        </button>
    </div> -->

    <!--        表格           -->
    <table id="tb_departments" style="font-size: 14px;"></table>

    <div class="modal fade" id="jiesuanModel" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog" style="width: 60%;height: 50%">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                    <h4 class="modal-title" id="salePlanModelLabel">结算</h4>
                </div>

                <input id="jsindex" hidden="hidden">
                <input id="lastMonthP" style="width: 80%" placeholder="期初应收">
                <input id="monthCollectP" style="width: 80%" placeholder="本期收款">

                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary" onclick="jisuangb()" id="backOutLib">确定</button>
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal-dialog -->
    </div>
</div>

    <script>




        function jisuangb(){
            var index = $("#jsindex").val();
            var row = $('#tb_departments').bootstrapTable('getData')[index];
            var lastMonthP = $("#lastMonthP").val();
            var monthCollectP = $("#monthCollectP").val();
            //首先查询后台 是否对本期过帐（根据时间查）
            //var row = $('#tb_departments').bootstrapTable('getData')[index];
            if (row) {
                $.ajax({
                    url: "${pageContext.request.contextPath }/yzl/checkIsDz.do",//应收结算
                    type: "POST",
                    data : {customerId : row.customerId,dateMonth : row.dateMonth,lastMonthP:lastMonthP,monthCollectP:monthCollectP},
                    //contentType: "application/json; charset=utf-8",
                    success: function (data) {
                        /*if(data > 0){//大于0 说明对过帐  填写期初金额 和 本期收款金额

                        }else{//说明没有对账  跳转至对账
                            parent.tab.tabAdd({
                                href: "/pages/yzlERP/salesReconciliation/salesReconciliation.jsp?id="+row.customerId, //地址
                                icon: "",
                                title: "对账"
                            });
                        }*/
                    }
                })
            }
        }

        function jiesuanYs(index) {

            $('#jiesuanModel').modal({
                keyboard: true,
            })
            $("#jsindex").val(index);

            /*//必须选中一条数据
            var row = $('#tb_departments').bootstrapTable('getData')[index];

            if(row){
                parent.tab.tabAdd({
                    href: "/pages/yzlERP/salesReconciliation/salesReconciliation.jsp?id="+row.customerId, //地址
                    icon: "",
                    title: "对账"
                });
                //toastr.warning('不支持批量修改,默认修改选中的第一行');
            }else{
                toastr.warning('请选择一行信息');
            }*/
        }

        $(document).ready(function () {

            $("#btn_report").click(function (){
                parent.tab.tabAdd({
                    href: "${pageContext.request.contextPath}/pages/yzlERP/salesReceivable/histogram.jsp", //地址
                    icon: "",
                    title: "对账"
                });
            })

            $("#btn_add").click(function () {

                $('#td_addModelTable').bootstrapTable({
                    dataType: "json",
                    method: 'get',
                    contentType: "application/x-www-form-urlencoded",
                    cache: false,
                    toolbar: '#toolbarIn',
                    url: "${pageContext.request.contextPath}/pages/yzlERP/data/saleOutCarList.json",
                    columns: [
                        [
                            {
                                field: 'name',
                                title: "出库单号",
                                valign: "middle",
                                align: "center",
                                colspan: 1
                            },
                            {
                                title: "00000000001",
                                valign: "middle",
                                align: "center",
                                colspan: 1,
                            },
                            {
                                title: "出库日期",
                                valign: "middle",
                                align: "center",
                                colspan: 1,
                            },
                            {
                                title: "2222-2-22",
                                valign: "middle",
                                align: "center",
                                colspan: 1,
                            },
                            {
                                title: "制单人",
                                valign: "middle",
                                align: "center",
                                colspan: 1,
                            },
                            {
                                title: "鬼",
                                valign: "middle",
                                align: "center",
                                colspan: 1,
                            }
                        ],
                        [
                            {
                                field: 'name',
                                title: "客户",
                                valign: "middle",
                                align: "center",
                                colspan: 1
                            },
                            {
                                title: "鬼",
                                valign: "middle",
                                align: "center",
                                colspan: 1,
                            },
                            {
                                title: "销售计划单号",
                                valign: "middle",
                                align: "center",
                                colspan: 1,
                            },
                            {

                                //title: "鬼",
                                //valign:"middle",
                                field: 'aa',
                                align: "center",
                                colspan: 1,
                                formatter: function (value, row, index) {
                                    var back = index;
                                    return '<a href="#" onclick="chosePlanNum(' + back + ')" >选择销售计划</a>'
                                }
                            },
                            {
                                title: "审批人",
                                valign: "middle",
                                align: "center",
                                colspan: 1,
                            },
                            {
                                title: "鬼",
                                valign: "middle",
                                align: "center",
                                colspan: 1,
                            }
                        ],
                        [
                            {
                                field: 'carType',
                                title: '车种',
                                valign: "middle",
                                align: "center"
                            },
                            {
                                field: 'numberP',
                                title: '品编',
                                valign: "middle",
                                align: "center"
                            },
                            {
                                field: 'nameP',
                                title: '品名',
                                valign: "middle",
                                align: "center"
                            },
                            {
                                field: 'batchNumber',
                                title: '批号',
                                valign: "middle",
                                align: "center"
                            },
                            {
                                field: 'outQ',
                                title: '出库数量',
                                valign: "middle",
                                align: "center"
                            },
                            {
                                field: 'barderNumber',
                                title: '条码',
                                valign: "middle",
                                align: "center"
                            }
                        ]
                    ]
                });

                var allRows = $("#tb_departments").bootstrapTable("getData");
                $('#myModal').modal({
                    keyboard: true,
                })
            });
            $("#btn_edit").click(function () {

                if ($('#checkbox-id').is(':checked')) {
                    console.log(222222222222);
                }

                $('#myModalUpdate').modal({
                    keyboard: true,
                })
            });
            $("#btn_delete").click(function () {

                if ($('#checkbox-id').is(':checked')) {
                    console.log(333333333333);
                }

                $('#myModalDelete').modal({
                    keyboard: true,
                })
            });

            //选择销计划单号
            function chosePlanNum() {
            	toastr.warning(1111111111);
            }

            //提交审核
            $("#btn_approved").click(function () {
                //必须选中一条数据
                var checkedItems = $('#tb_departments').bootstrapTable('getSelections');
                var checkedItem = checkedItems[0];
                if (checkedItems <= 0) {
                    //$("#btn_edit").attr("data-toggle", "");
                    //$("#btn_edit").attr("data-target", "");
                    toastr.warning('请选择一行信息');
                } else {
                    console.log("checkedItems----", checkedItems);
                    var arr = filterData(checkedItems);
                    console.log("arr", arr);
                    if (arr) {
                        //执行后台
                        $.ajax({
                            url: "${pageContext.request.contextPath}/yzl/orderApproveds.do",
                            type: "post",
                            data: {"arr": JSON.stringify(arr)},
                            success: function (data) {
                                if (data != 0) {
                                    toastr.info('操作成功');
                                    refreshAjax();
                                } else {
                                    toastr.warning('操作失败');
                                }
                            }
                        })
                    } else {
                        toastr.warning('不能选择审核中的审核通过的');
                    }
                }
            })
        });

        $("#btn_jiesuanAll").click(function () {
            //进入后台结算  完成后需要刷新表格
            $.ajax({
                url: "${pageContext.request.contextPath }/yzl/ReceivableJs.do",//应收结算
                type: "GET",
                contentType: "application/json; charset=utf-8",
                success: function (data) {
                    /*if(data == 1){
                        alert("操作成功！");
                    }else{
                        alert("操作失败！");
                    }*/
                }
            })
        })

        $("#btn_query").click(function (){
	    	//var recent=$('#recent option:selected').val()
	    	var beginDate=$('#beginDate').val();
	    	//var endDate=$('#endDate').val();
	    	$("#tb_departments").bootstrapTable('refresh', {url: '${pageContext.request.contextPath }/hpf/receivableList.do?beginDate='+beginDate});
	    })
        
        //点击查询 重新请求  刷新表格
        function refreshAjax() {
            $("#tb_departments").bootstrapTable('refresh', {url: '${pageContext.request.contextPath }/yzl/receivableList.do'});
        }
        /* laydate.render({
        	elem: '#beginDate'
        	,type: 'month'
        	,max: 0
        }); */
        $(".form_datetime").datetimepicker({
        	language:  'zh-CN',
            format: 'yyyy-mm',
            autoclose: true,
            todayBtn: true,
            startView: 'year',
            minView:'year',
            maxView:'decade',
            endDate: new Date()
        })
    </script>


    <script>
        layui.use(['form', 'layedit', 'laydate'], function () {
            var form = layui.form(),
                layer = layui.layer,
                layedit = layui.layedit,
                laydate = layui.laydate;

            //创建一个编辑器
            var editIndex = layedit.build('LAY_demo_editor');
            //自定义验证规则
            form.verify({
                title: function (value) {
                    if (value.length < 5) {
                        return '标题至少得5个字符啊';
                    }
                },
                pass: [/(.+){6,12}$/, '密码必须6到12位'],
                content: function (value) {
                    layedit.sync(editIndex);
                }
            });

            //监听提交
            form.on('submit(demo1)', function (data) {
                layer.alert(JSON.stringify(data.field), {
                    title: '最终的提交信息'
                })
                return false;
            });
        });


    </script>
</body>
</html>
